Skip to content

feat: expose teamsctl as a public Go SDK - #14

Merged
TheSinding merged 2 commits into
mainfrom
feat/public-go-sdk
Aug 6, 2026
Merged

feat: expose teamsctl as a public Go SDK#14
TheSinding merged 2 commits into
mainfrom
feat/public-go-sdk

Conversation

@TheSinding

Copy link
Copy Markdown
Owner

Moves the Teams client out of internal/ into pkg/ (teamsauth + teamsctl) so other Go projects can import it, and exports the service API (ResolveConversationTarget, FindOneOnOneConversation, Me/Identity, Message/SendOptions, etc.). CLI and MCP wiring stay internal and consume the pkg packages.

Also fixes the blank message author for the signed-in user: Teams leaves imDisplayName empty on your own messages, so Messages now substitutes the account's display name when the sender MRI matches (directly, or derived from objectId) and exposes sender_id.

Verified: go build, go vet clean; go test = 35 passed / 5 packages.

Move the Teams client out of internal/ into pkg/ (teamsauth + teamsctl) so other Go projects can import it, and export the service API: ResolveConversationTarget, ResolveIndividualTargets, FindOneOnOneConversation, FindGroupConversation, Me/Identity, and the Message/SendOptions types. CLI and MCP wiring stay internal and consume the pkg packages.

Backfill the message author for the signed-in user: Teams leaves imDisplayName empty on your own messages, so Messages now substitutes the account's display name when the sender MRI matches (directly, or derived from objectId), and exposes sender_id.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes teamsctl as a public Go SDK by moving the Teams auth/client logic into pkg/teamsauth + pkg/teamsctl, while keeping CLI/MCP wiring internal. It also improves message author attribution by backfilling the signed-in user’s display name when Teams omits it and adds sender_id to message records.

Changes:

  • Introduces public SDK surface in pkg/teamsctl (conversations resolution, sending, identity, message author backfill).
  • Introduces pkg/teamsauth for token storage (keyring + file fallback) and OAuth automation helpers.
  • Rewires internal CLI and MCP server to consume the new pkg/* packages.

Reviewed changes

Copilot reviewed 10 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/teamsctl/service.go Updates auth import path and adds cached best-effort currentUser() helper.
pkg/teamsctl/service_test.go Adds a test ensuring NewService passes keyring tokens to the Teams API client constructor.
pkg/teamsctl/send.go Adds public Service.Send plus mention resolution and message formatting utilities.
pkg/teamsctl/send_test.go Adds tests for formatting and mention substitution helpers.
pkg/teamsctl/resolve.go Adds public recipient phrase resolution (ResolveConversationTarget, one-on-one/group lookup helpers).
pkg/teamsctl/resolve_test.go Updates tests to reflect refactor/moves of helper functions.
pkg/teamsctl/models.go Extends Message model with SenderID.
pkg/teamsctl/messages.go Backfills self-message author name and exposes SenderID; factors mapping into messageRecords.
pkg/teamsctl/messages_test.go Adds tests for self-sender detection and author backfill behavior.
pkg/teamsctl/identity.go Adds public Me() identity accessor that returns a stable SDK Identity type.
pkg/teamsctl/conversations.go Adds conversation discovery/filtering, caching/enrichment, and shared ID utilities.
pkg/teamsctl/conversations_test.go Adds test asserting one-on-one chats are preferred in filtering.
pkg/teamsauth/tokens.go Adds token validation/loading and keyring-first storage with file fallback.
pkg/teamsauth/tokens_test.go Adds tests for expiry validation, config dir resolution, keyring/file fallback behavior, and CheckTokens.
pkg/teamsauth/oauth.go Adds OAuth URL building + callback parsing and tenant discovery helper.
pkg/teamsauth/oauth_test.go Adds tests for auth URL formation and callback parsing behaviors.
pkg/teamsauth/models.go Adds options and internal auth model types (claims, tenants, token kinds).
pkg/teamsauth/command.go Adds an auth subcommand runner for internal CLI to call into the auth workflow.
pkg/teamsauth/browser.go Implements the Chrome/chromedp-based multi-token auth flow and Chrome path resolution.
pkg/teamsauth/browser_test.go Adds tests for resolving direct executables vs macOS app bundles.
pkg/teamsauth/autofill.go Adds best-effort login form autofill loop for chromedp-based auth.
internal/teamsctl/mcp.go Switches MCP server implementation to use the new pkg/teamsctl SDK APIs/types.
internal/teamsctl/cli.go Switches internal CLI to use pkg/teamsauth and pkg/teamsctl instead of internal client/auth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/teamsctl/cli.go Outdated
Comment on lines 133 to 137
ids := strings.Split(flags.Arg(0), ",")
if err = service.Send(ids, content, tctl.SendOptions{Format: *format, Mentions: mentions}); err != nil {
return err
}
return writeJSON(stdout, map[string]interface{}{"sent": true, "conversation_ids": ids})
Export SplitIDs from pkg/teamsctl and use it in the CLI so the send output reports the same normalized IDs (trimmed, deduped, non-empty) that Service.Send actually messages, instead of the raw comma split. Restores the pre-refactor normalization in messages/send.
@TheSinding
TheSinding merged commit 15e1cf6 into main Aug 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants